<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<title>注册</title>
<link rel="stylesheet" href="style/css/base.css" />
<link rel="stylesheet" href="style/css/login.css" />

<script type="text/javascript" src="style/js/jquery-1.7.1.min.js"></script>


<!-- 验证码 -->
<style>
.verify {
	width: 95px;
	position: absolute;
	right: 0;
	top: 0px;
	cursor: pointer;
	height: 46px;
	font-size: 14px;
	text-align: center;
	line-height: 46px;
	background-color: rgb(50, 165, 231);
	color: black;
}

::-webkit-scrollbar {
	display: none;
}
</style>



</head>
<body>
	<div id="content" class="content">


		<div class="banner-box">
			<form id="mainForm" class="main-form"
				enctype="application/x-www-form-urlencoded" novalidate="novalidate">
				<div class="tab-title">
					<a class="linkAGray" id="toAccountLogin" href="login.html">账号登录</a>
					<span class="register-line"></span> <a class="linkAGray"
						id="toVCodeLogin" href="register.html">账号注册</a>
					<!-- <span class="register-line"></span> <a class="linkABlue"
						id="toVCodeLogin" style="display:none;">账号注册</a> -->
				</div>

				<div id="errorMsg" class="tip-box visiblility-hidden">
					<i class="err-ico"></i> <span class="tip-font" id="tipMsg">请填写完整的注册信息</span>
					<span id="closeErrorMsg" class="close-ico"></span>
				</div>


				<div class="normalInput cycode-box fieldInput" id="cycode-box">
					<div class="cycode-selectbox">
						<input class="ipt-account inp-focus" name="email" id="email"
							maxlength="50" placeholder="请输入要找回的账户名" autocomplete="off"
							onfocus="closeErrorMsg()" />

					</div>

				</div>
				<div class="normalInput cycode-box fieldInput" id="cycode-box">
					<div class="cycode-selectbox">
						<input class="ipt-account inp-focus" name="email" id="passwordtwo"
							maxlength="50" placeholder="请输入新密码" autocomplete="off"
							type="password" onfocus="closeErrorMsg()" />

					</div>

				</div>
				<div class="normalInput cycode-box fieldInput" id="cycode-box">
					<div class="cycode-selectbox">
						<input class="ipt-account inp-focus" name="email" id="passwordone"
							maxlength="50" placeholder="请确认新密码" autocomplete="off"
							type="password" onfocus="closeErrorMsg()" />

					</div>

				</div>
				<div class="normalInput fieldInput">
					<input type="text" class="inp-focus" name="Verificationcode"
						id="Verificationcode" maxlength="16" autocomplete="off"
						placeholder="验证码" onfocus="closeErrorMsg()" /> <span
						id="verifyCode" class="verify" onclick="sendsms(this);">获取验证码</span>
				</div>

				<a id="forgetpwd" class="fullBtnBlue">确认修改</a>


			</form>



		</div>
	</div>




	<script>
  	//点击确认修改
  	$("#forgetpwd").click(function(){  
    		var account = $("#email").val();
    		var passwordone = $("#passwordone").val();
    		var passwordtwo = $("#passwordtwo").val();
			var Verificationcode = $("#Verificationcode").val(); //输入的验证码
			

			if( email=="" || Verificationcode==""){
				var obj = document.getElementById("errorMsg");
				$("#tipMsg").html("请填写完整的注册信息！");
				obj.setAttribute("class", "tip-box visiblility-show");
				return ;
			}
			//邮箱校验
			var reg =/^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
			var t = account.match(reg);
			if( t == null ){
				//提示错误信息
				var obj = document.getElementById("errorMsg");
				//修改提示文字
				$("#tipMsg").html("请填写正确的邮箱！");
				obj.setAttribute("class", "tip-box visiblility-show");
				return ;
			}
			if(passwordone!=passwordtwo){
				alert("两次密码输入不一致！请重新输入！！")
				return;
			}
			//发送请求注册
			if(Verificationcode!=code){
				//校验验证码
				alert("验证码填写错误！请重新输入！！！")
			}else{
				//发送ajax请求
				$.ajax({
					  type: 'POST',
					  url: '/forgetpwd',
					  data: 'account='+account+'&passwordone='+passwordone+'&passwordtwo='+passwordtwo,
					  dataType: 'JSON',
					  success: function(data){
						  if(data==true){
						 alert("恭喜您 "+account+" 密码修改成功！！！\n请牢记您的新密码："+passwordone);
						 window.location.href='login.html';
						 }else{
							 alert("用户不存在！请注册用户！！！");
						 }
					  },
				});
			}


	});  

  	//点击错误信息关闭按钮
  	$("#closeErrorMsg").click(function(){
			var obj = document.getElementById("errorMsg");
			obj.setAttribute("class", "tip-box visiblility-hidden");
  	});



  	//关闭错误提示
  	function closeErrorMsg(){
  			var obj = document.getElementById("errorMsg");
			obj.setAttribute("class", "tip-box visiblility-hidden");
  	}


    //发送验证码函数
    function sendsms(e){
    	var email = $("#email").val();
    	if( email==""){
			//提示错误信息
			var obj = document.getElementById("errorMsg");
			//修改提示文字
			$("#tipMsg").html("请填写正确的邮箱！");
			obj.setAttribute("class", "tip-box visiblility-show");
			return ;
    	}
		//邮箱校验
		var reg =/^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
		var t = email.match(reg);
		if( t == null ){
			//提示错误信息
			var obj = document.getElementById("errorMsg");
			//修改提示文字
			$("#tipMsg").html("请填写正确的邮箱！");
			obj.setAttribute("class", "tip-box visiblility-show");
			return ;
		}



    	/* //发送ajax请求，后台发送邮件
		$.ajax({
			  type: 'POST',
			  url: 'register.action',
			  data: 'email='+email
		}); */
		 var arrays=new Array(  
			        '1','2','3','4','5','6','7','8','9','0'
			    );  
			    code='';//重新初始化验证码  
			    //alert(arrays.length);  
			    //随机从数组中获取四个元素组成验证码  
			    for(var i=0;i<4;i++){  
			    //随机获取一个数组的下标  
			        var r=parseInt(Math.random()*arrays.length);  
			        code+=arrays[r];  
			        //alert(arrays[r]);  
			    } 
		alert(email+"向您发送了验证码，您的验证码为："+code)
        /*发送验证码功能*/
        countdown(e);     //若发送验证码成功，则调用倒计时函数
    }
    //倒计时函数
    var time = 5;
    function countdown(e){
         if (time == 0) {
             e.setAttribute("onclick","sendsms(this)");
             $("#verifyCode").html("获取验证码");
             //颜色恢复
             var mychar = document.getElementById("verifyCode");
             mychar.style.backgroundColor  = "rgb(50,165,231)";
             time = 5;
         }else{
             //设置背景为灰色
             var mychar = document.getElementById("verifyCode");
             mychar.style.backgroundColor  = "rgb(169,169,169)";

             e.removeAttribute("onclick");
             $("#verifyCode").html("重新发送(" + time + ")");
             time--;
             setTimeout(function() {
                 countdown(e)
             },1000)
         }
    }


  </script>
</body>
</html>